<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form ref="form" label-width="120px" style="margin-left: 120px; margin-top:30px" :model="formData" :rules="rules">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password2">
                <el-input v-model="formData.password2" style="width:300px" type="password2" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submit">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <keep-alive><component :is="UserInfo" ref="UserInfo" /></keep-alive>
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <keep-alive><component :is="JobInfopp" /></keep-alive>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>
<script>
import { getUserInfoDetailApi, saveUserDetailById } from '@/api/user'
import UserInfo from '@/views/employees/components/UserInfo.vue'
import JobInfopp from '@/views/employees/components/JobInfopp.vue'
export default {
  name: 'DetailEmployess',
  components: {
    UserInfo,
    JobInfopp
  },
  data() {
    return {
      UserInfo: 'UserInfo',
      JobInfopp: 'JobInfopp',
      formData: { username: '', password2: '' },
      userId: this.$route.params.id,
      rules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }
        ],

        password2: [{ required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 9, message: '长度在 5 到 9 位密码', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserinfo()
  },
  methods: {
    async getUserinfo() {
      console.log(this.$route)
      const res = await getUserInfoDetailApi(this.userId)
      console.log(res)
      this.formData = res
    },
    async submit() {
      await this.$refs.form.validate()
      await saveUserDetailById(
        { ...this.formData,
          password: this.formData.password2 }
      )
      this.$message.success('更新成功')
    }
  }
}
</script>
<style scoped></style>
